﻿using AssettDatabase.VO;
using System;
using System.Collections.Generic;
using System.Data;

namespace AssettDatabase.BLL
{
    class Customer
    {
        public bool Add(string Customer_Name, string Customer_Phone, string Customer_ABN, string Customer_Mobile, string Primary_Contact_FN, 
                        string Primary_Contact_LN, string Customer_Website, string Primary_Contact_Email, string Accounts_Payable_FN,
                        string Accounts_Payable_LN, string Accounts_Payable_EML, string Customer_Notes)
        {
            DAL.Customer mCustomer = new DAL.Customer();
            return mCustomer.Add(Customer_Name, Customer_Phone, Customer_ABN, Customer_Mobile, Primary_Contact_FN, 
                        Primary_Contact_LN, Customer_Website, Primary_Contact_Email, Accounts_Payable_FN, 
                        Accounts_Payable_LN, Accounts_Payable_EML, Customer_Notes);
        }

        public bool Update(string Customer_Name, string Customer_Phone, string Customer_ABN, string Customer_Mobile, string Primary_Contact_FN,
                string Primary_Contact_LN, string Customer_Website, string Primary_Contact_Email, string Accounts_Payable_FN,
                string Accounts_Payable_LN, string Accounts_Payable_EML, string Customer_Notes, string Customer_ID)
        {
            DAL.Customer mCustomer = new DAL.Customer();
            return mCustomer.Update(Customer_Name, Customer_Phone, Customer_ABN, Customer_Mobile, Primary_Contact_FN,
                        Primary_Contact_LN, Customer_Website, Primary_Contact_Email, Accounts_Payable_FN,
                        Accounts_Payable_LN, Accounts_Payable_EML, Customer_Notes, Customer_ID);
        }

        public bool Del(string Customer_ID)
        {
            DAL.Customer mCustomer = new DAL.Customer();
            return mCustomer.Del(Customer_ID);
        }

        public List<VO.Customer> GetCustomers()
        {
            List<VO.Customer> mList = new List<VO.Customer>();
            DAL.Customer mCustomer = new DAL.Customer();
            DataTable mDataTable = mCustomer.GetCustomers();

            foreach (DataRow dr in mDataTable.Rows)
            {
                VO.Customer voCustomer = new VO.Customer();
                voCustomer.Accounts_Payable_EML = dr["Accounts_Payable_EML"].ToString();
                voCustomer.Accounts_Payable_FN = dr["Accounts_Payable_FN"].ToString();
                voCustomer.Accounts_Payable_LN = dr["Accounts_Payable_LN"].ToString();
                voCustomer.Customer_ABN = dr["Customer_ABN"].ToString();
                voCustomer.Customer_ID = Convert.ToInt32(dr["Customer_ID"]);
                voCustomer.Customer_Mobile = dr["Customer_Mobile"].ToString();
                voCustomer.Customer_Name = dr["Customer_Name"].ToString();
                voCustomer.Customer_Notes = System.Text.Encoding.Default.GetString((byte[])dr["Customer_Notes"]);
                voCustomer.Customer_Phone = dr["Customer_Phone"].ToString();
                voCustomer.Customer_Website = dr["Customer_Website"].ToString();
                voCustomer.Primary_Contact_Email = dr["Primary_Contact_Email"].ToString();
                voCustomer.Primary_Contact_FN = dr["Primary_Contact_FN"].ToString();
                voCustomer.Primary_Contact_LN = dr["Primary_Contact_LN"].ToString();

                mList.Add(voCustomer);
            }

            return mList;
        }

        public List<VO.Customer> GetCustomerById(string Customer_ID)
        {
            List<VO.Customer> mList = new List<VO.Customer>();
            DAL.Customer mCustomer = new DAL.Customer();
            DataTable mDataTable = mCustomer.GetCustomerById(Customer_ID);

            foreach (DataRow dr in mDataTable.Rows)
            {
                VO.Customer voCustomer = new VO.Customer();
                voCustomer.Accounts_Payable_EML = dr["Accounts_Payable_EML"].ToString();
                voCustomer.Accounts_Payable_FN = dr["Accounts_Payable_FN"].ToString();
                voCustomer.Accounts_Payable_LN = dr["Accounts_Payable_LN"].ToString();
                voCustomer.Customer_ABN = dr["Customer_ABN"].ToString();
                voCustomer.Customer_ID = Convert.ToInt32(dr["Customer_ID"]);
                voCustomer.Customer_Mobile = dr["Customer_Mobile"].ToString();
                voCustomer.Customer_Name = dr["Customer_Name"].ToString();
                voCustomer.Customer_Notes = System.Text.Encoding.Default.GetString((byte[])dr["Customer_Notes"]);
                voCustomer.Customer_Phone = dr["Customer_Phone"].ToString();
                voCustomer.Customer_Website = dr["Customer_Website"].ToString();
                voCustomer.Primary_Contact_Email = dr["Primary_Contact_Email"].ToString();
                voCustomer.Primary_Contact_FN = dr["Primary_Contact_FN"].ToString();
                voCustomer.Primary_Contact_LN = dr["Primary_Contact_LN"].ToString();

                mList.Add(voCustomer);
            }

            return mList;
        }

        public List<VO.Customer> GetCustomerByName(string Customer_Name)
        {
            List<VO.Customer> mList = new List<VO.Customer>();
            DAL.Customer mCustomer = new DAL.Customer();
            DataTable mDataTable = mCustomer.GetCustomerByName(Customer_Name);

            foreach (DataRow dr in mDataTable.Rows)
            {
                VO.Customer voCustomer = new VO.Customer();
                voCustomer.Accounts_Payable_EML = dr["Accounts_Payable_EML"].ToString();
                voCustomer.Accounts_Payable_FN = dr["Accounts_Payable_FN"].ToString();
                voCustomer.Accounts_Payable_LN = dr["Accounts_Payable_LN"].ToString();
                voCustomer.Customer_ABN = dr["Customer_ABN"].ToString();
                voCustomer.Customer_ID = Convert.ToInt32(dr["Customer_ID"]);
                voCustomer.Customer_Mobile = dr["Customer_Mobile"].ToString();
                voCustomer.Customer_Name = dr["Customer_Name"].ToString();
                voCustomer.Customer_Notes = System.Text.Encoding.Default.GetString((byte[])dr["Customer_Notes"]);
                voCustomer.Customer_Phone = dr["Customer_Phone"].ToString();
                voCustomer.Customer_Website = dr["Customer_Website"].ToString();
                voCustomer.Primary_Contact_Email = dr["Primary_Contact_Email"].ToString();
                voCustomer.Primary_Contact_FN = dr["Primary_Contact_FN"].ToString();
                voCustomer.Primary_Contact_LN = dr["Primary_Contact_LN"].ToString();

                mList.Add(voCustomer);
            }

            return mList;
        }
    }
}
